/**
 * @Description 留宿申请的控制层
 * @author 20155870 杨润增
 * @create 2018-05-06 14:11
 **/
package com.campus_information_portal.controller;

import com.campus_information_portal.entity.DorStuTerm;
import com.campus_information_portal.entity.DormitoryApplyForm;
import com.campus_information_portal.service.DormitoryService;
import com.campus_information_portal.service.StudentService;
import com.campus_information_portal.service.TermService;
import com.campus_information_portal.util.Message;
import com.campus_information_portal.util.Msg;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.net.UnknownHostException;
import java.util.Date;
import java.util.Map;

/**
 * @className DormitoryController
 * @Description 宿舍管理的控制层
 * @author 20155870 杨润增
 * @create 2018-05-06 14:11
 **/
@Controller
@RequestMapping("/dormitory")
@ResponseBody
@CrossOrigin(origins = "*")
public class DormitoryController {
    @Autowired
    private DormitoryService dormitoryService;


    @RequestMapping(value = "/queryMyApplys",method = RequestMethod.GET)
    public Message queryMyDormitoryApplyForms(DorStuTerm dorStuTerm){
        System.out.println(dormitoryService.queryApplyByConditions_2(dorStuTerm));
        return dormitoryService.queryApplyByConditions_2(dorStuTerm);
    }

    @RequestMapping(value = "/applyDor",method = RequestMethod.GET)
    public Message apply(@Param("stuNum")Integer stuNum,
                     @Param("termYear")String termYear, @Param("termNum")String termNum,
                     @Param("startDate")Date startDate, @Param("endDate")Date endDate,
                     @Param("reason")String reason){
        return dormitoryService.addApply_3(stuNum,termYear,termNum,startDate,endDate,reason);
    }

    @RequestMapping(value = "/download",method = RequestMethod.GET)
    public Message download(@Param("stuName")String stuName,
                         @Param("stuSex")String stuSex, @Param("dormitoryNum")int dormitoryNum,
                         @Param("startDate")String startDate, @Param("endDate")String endDate) throws UnknownHostException {
        System.out.println(stuName);
        System.out.println(stuSex);
        System.out.println(dormitoryNum);
        System.out.println(startDate);
        System.out.println(endDate);
        return dormitoryService.download(stuName,stuSex,dormitoryNum,startDate,endDate);

    }

    @RequestMapping(value = "/agree",method = RequestMethod.GET)
    public Message agree(@Param("dormitoryApplyFormId")Integer dormitoryApplyFormId) {
        return dormitoryService.agreeApply(dormitoryApplyFormId);
    }

    @RequestMapping(value = "/refuse",method = RequestMethod.GET)
    public Message refuse(@Param("dormitoryApplyFormId")Integer dormitoryApplyFormId) {
        return dormitoryService.refuseApply(dormitoryApplyFormId);
    }



}
